<?php
 //============================================================================
 // ____________________________PLIGG TEAM ADDON_______________________________
 //
// This CLASS was created by AnAlienHolakres3 ||| XXXXX  XX     XX XXXX   XXXX
// (c) 2007-2008                Jakub Holasek ||| XXXXX  XX     XX X      X
// @last_update                    02/08/2008 ||| XX     XX     XX X  XX  X  XX
// @version                              0.13 ||| XX     XXXXXX XX XXXXX  XXXXX
//
// This file can be used by Pligg community.
//=============================================================================

// Class Task contains general information about tasks

class Task {
 
    private $id =0;
    private $team_id=0; 
    
    private $worker_id=0;       
    private $name=''; 
    private $description='';
    private $completeness=0;          
    private $deadline=0;
    private $setup_date=0;
    private $last_modify=0;
    private $user_tasks=0;
    private $user_team_tasks=0;
    
    private $tasks_data=0;
    private $tasks_ids=0; 
   //settings 
   private $minimal_description_length=12;
   private $minimal_name_length=3; 
   // if any team member can add task to himself
   private $team_member_own_task = true;
   
   private $read = true;
    
    //============================================================================
    //  Function read_task_ids() gets tasks ids
    //============================================================================      
     function read_task_ids() {
      global $db;      
      
      $team_id = $this->team_id;           
      
      if(($ids = $db->get_results("SELECT task_id FROM " . table_tasks .
       " WHERE task_team_id=$team_id"))){   
  
       $this->tasks_ids=$ids;
      
         $this->read        = true;
         return true;                           
         }
         $this->read        = false;
         return false;
         
         
     }

    
     //============================================================================
    //  Function read_basic() gets data of 1 specific task
    //============================================================================      
     function read_basic() {
      global $db;
      
      $id = $this->id;
      $team_id = $this->team_id;
           
      
      if(($task = $db->get_row("SELECT task_worker_id, task_name, task_description,task_deadline FROM " . table_tasks .
       " WHERE task_id= $id AND task_team_id=$team_id"))){   
        
        $this->name         = $task->task_name;
        $this->description  = $task->task_description;        
        $this->worker_id    = $task->task_worker_id;
        $this->deadline     = $task->task_deadline;
        
         
      
         $this->read        = true;
         return true;                           
         }
         $this->read        = false;
         return false;
         
         
     }
     
    
    //============================================================================
    //  Function read_task() gets task data (array) from database    
    //============================================================================      
    
    function read_tasks() {
        global $db;
        
        $id = $this->id; 
        $team_id = $this->team_id;
        
        $sort_by = $this->get_sort();
        $filter_by = $this->get_filter();              
        
           //if this query changes, change it in task_summary.php
           $task = $db->get_results("SELECT " . table_tasks . ".*,user_login FROM " . table_tasks . " 
            JOIN " . table_users . " ON " . table_users.".user_id=" . table_tasks . ".task_worker_id WHERE task_team_id = $team_id
              $filter_by $sort_by");
                    
        
        if ($task) {
         
         $this->tasks_data = $task;         
         return true;    
        }
        
        $this->fullread = $this->read = false;
        return false;
    } 
      //============================================================================
      //  Function read_user_tasks() read all user tasks
      //  To be specific it returns all team tasks where is user team member,
      //  team member can add link to team tasks which are not its own 
      //  If you want to allow add link to tasks for task workers only just uncomment
      //  used by Ajax      
      //============================================================================
      
      function read_user_tasks(){ 
         global $db,$current_user;                        
                                
          $tasks = $db->get_results("  SELECT task_id,team_id,task_name,team_name,task_worker_id FROM "
                                    . table_tasks . " JOIN " . table_teams . " ON " . table_teams . ".team_id = " . table_tasks . ".task_team_id WHERE team_id
                                     IN (SELECT team_id FROM ".table_membership. " WHERE user_id=$current_user->user_id) OR team_id IN (SELECT team_id FROM "
                                     . table_teams . " WHERE team_creator_id=$current_user->user_id)");
                                
           
           // allow only team workers to add links to task  
          //$tasks = $db->get_results("SELECT task_id,team_id,task_name,team_name,task_worker_id FROM " . table_tasks . "
          //   JOIN ".table_teams." ON ". table_teams . ".team_id = ".table_tasks. ".task_team_id WHERE task_worker_id ="
          //   .$current_user->user_id ." ORDER BY team_name ASC");
            
      if ($tasks) {
         
         $this->user_tasks = $tasks;
         return true;    
        }
         return false;                     
      }
      
      //============================================================================
      //  Function read_user_team_tasks() read all user tasks in specific team      
      //============================================================================
      
      function read_user_team_tasks($user_id){ 
         global $db;
           
           $team_id=$this->team_id;                     
                                
          $tasks = $db->get_results("  SELECT task_id FROM " . table_tasks . " WHERE task_team_id=$team_id
                                     AND task_worker_id = $user_id");                                                                            
            
      if ($tasks) {
         
         $this->user_team_tasks = $tasks;
         return true;    
        }
         return false;                     
      }
      
      //============================================================================
      //  Function get_task_worker() read task worker_id from database
      //  @param task_id
      //============================================================================
      
      function get_task_worker(){ 
         global $db;
         $task_id = $this->id;
                                                                             
          $worker = $db->get_var("  SELECT task_worker_id FROM " . table_tasks . " WHERE task_id=$task_id");                                                                               return $worker;
            
                      
      }
      
      //============================================================================
      //  Function get_task_name() read task name from database
      //  @param task_id
      //============================================================================
      
      function get_task_name(){ 
         global $db;
          $task_id=$this->id;                                                          
         $name = $db->get_var("  SELECT task_name FROM " . table_tasks . " WHERE task_id=$task_id");                                                                                     return $name;
            
                      
      }
      
    //============================================================================
      //  Function fill_print() assign team task smartys
      //============================================================================
      
      function fill_print($mode)
      {
          global $main_smarty;
          
          $tasks_data = $this->tasks_data;
          $team = new Team;
          $language = $team->get_language();                        
          $id = $this->id;
        $name = $this->name;       
          $description   = $this->description;
          $worker = $this->worker_id;
          $deadline=$this->deadline;
                                                                
          $taskComment = new TaskComment;
          $main_smarty->assign('minimal_taskcomment_length',$taskComment->get_minimum_taskcomment_length());
          
       if ($mode == "full") {
          if ($tasks_data) {
              foreach ($tasks_data as $task) {
                  
                  $tasks_id[] = $task->task_id;
                  $tasks_name[] = $task->task_name;
                  $tasks_description[] = str_replace(array("\n", "\r"),"<br />",$task->task_description);
                  $tasks_worker[] = $task->user_login;
                  $tasks_worker_id[] = $task->task_worker_id;
                  $tasks_completeness[] = $task->task_completeness;                 
                  $tasks_deadline_bin[] = strtotime($task->task_deadline);    
                   
                  if ($language == "en"){
                  $tasks_date[] = date('Y/d/m h:i a',strtotime($task->task_date)); 
                  $tasks_last_modify[] = date('Y/d/m h:i a',strtotime($task->task_last_modify)); 
                  $tasks_deadline[] = date("d/m/Y", strtotime($task->task_deadline));
                  $tasks_deadline_show[] = $task->task_deadline;
                  
                  } else {                                       
                  $tasks_date[] = date('d.m.Y H:i',strtotime($task->task_date)); 
                  $tasks_date[] = date('d.m.Y H:i',strtotime($task->task_date)); 
                  $tasks_deadline[] = date("d/m/Y", strtotime($task->task_deadline));
                  $tasks_deadline_show[] = date("d.m.Y", strtotime($task->task_deadline));
                  
                  
                  }
                  
                  //for update
                  if ($id == $task->task_id) {            
                       $task_id = $id;
                       $task_name = $task->task_name;
                       $task_description = $task->task_description;
                       $task_worker = $task->task_worker_id;               
                       $task_deadline = date("d/m/Y", strtotime($task->task_deadline));
                       
                      
                  }
                  
              }                                     
                $main_smarty->assign('today_date',time());                 
                $main_smarty->assign('team_tasks_id', $tasks_id);
                $main_smarty->assign('team_tasks_name', $tasks_name);
                $main_smarty->assign('team_tasks_description', $tasks_description);
                $main_smarty->assign('team_tasks_deadline_bin',$tasks_deadline_bin); 
                $main_smarty->assign('team_tasks_deadline', $tasks_deadline);
                $main_smarty->assign('team_tasks_deadline_show', $tasks_deadline_show);
                $main_smarty->assign('team_tasks_worker_id',$tasks_worker_id);
                $main_smarty->assign('team_tasks_date', $tasks_date); 
                $main_smarty->assign('team_tasks_worker',$tasks_worker); 
                $main_smarty->assign('team_tasks_completeness',$tasks_completeness); 
             }
              } 
          if ($mode == "basic") {                              
                $main_smarty->assign('task_id',$this->id);
                $main_smarty->assign('task_name',$this->name);
                $main_smarty->assign('task_description',$this->description);
                $main_smarty->assign('task_worker',$this->worker_id);
                $main_smarty->assign('task_deadline',date("d/m/Y", strtotime($this->deadline)));  
                  
          }
         
          $main_smarty->assign('minimal_task_name_length',$this->minimal_name_length);
          $main_smarty->assign('minimal_task_description_length',$this->minimal_description_length);
       
      } 
    
    //============================================================================
    //  Function store() saves task data in database
    //============================================================================
    
    function store() {
        global $db;
    
        if(!$this->setup_date) $this->setup_date=time();
        if(!$this->last_modify) $this->last_modify=time();
        
        
        $task_id                 = $this->id;      
        $team_id            = $this->team_id;  
        $worker_id          = $this->worker_id;
        $name               = $this->name;                                                                          
        $description        = $this->description;                        
        $setup_date         = $this->setup_date;
        $last_modify        = $this->last_modify;
        $deadline           = $this->deadline;  
                     
        if($this->id===0) {   
         
           $sql = ("INSERT INTO " . table_tasks . " (task_team_id,task_worker_id, task_name, task_description, 
                      task_date, task_last_modify, task_deadline) VALUES ($team_id,$worker_id, '$name', '$description', 
                     FROM_UNIXTIME($setup_date), FROM_UNIXTIME($last_modify), '$deadline')");                                 
       
       } else {
                         
          $sql = "UPDATE " . table_tasks . " SET task_worker_id = $worker_id, task_name = '$name', task_description = '$description',
                  task_last_modify = FROM_UNIXTIME($last_modify),
                 task_deadline = '$deadline' WHERE task_id=$task_id AND task_team_id = $team_id";            
            
            }
    if($db->query($sql)){ 
          return true;     
          
                }     
          return false;
     }   
            
     //============================================================================
    //  Function delete_task() delete team task from database
    //  Please note - when task is deleted - all task files,,comments etc
    //  is DELETED ALSO!
    //============================================================================   
    
    function delete_task() {
        global $db;
                      
        $id = $this->id;
        $team_id = $this->team_id;
        
        
        $sql="DELETE FROM ". table_tasks. " WHERE  task_team_id=$team_id AND task_id = $id";  
                      
        
        if($db->query($sql)){ 
          return true;     
          
                }     
          return false;              
                                            
        
    } 
    
    
     //============================================================================
    //  Function duplicate_name() finds out if task name is (in team) unique
    //============================================================================   
    
    function duplicate_name() {
        global $db;
                      
        $task_name= $_POST['task_name'];
        $team_id = $this->team_id;
        
        $task_name=$db->escape(strip_tags($task_name));    
        $n = $db->get_var("SELECT count(*) FROM " . table_tasks . " WHERE task_name = '$task_name' AND task_team_id = $team_id");  
        return $n;
    }
    
    
    //============================================================================
    //  Function task_exist() finds out if there is some task in database
    //  @return true if task exist, otherwise false
    //  @param team_id
    //============================================================================      
    
    function task_exist($team_id) {
        global $db;        
               
        $exist=$db->get_var("SELECT team_id FROM " . table_tasks . " WHERE task_team_id=$team_id");


        if ($exist) { 
         return true; 
        }
        return false;
    }
    
    //============================================================================
    //  Function specific_task_exist() finds out if specific task exists
    //  @return true if task exist, otherwise false
    //  @param task_id
    //============================================================================      
    
    function specific_task_exist() {
        global $db;        
       
       $task_id = $this->id;        
        $exist=$db->get_var("SELECT task_id FROM " . table_tasks . " WHERE task_id=$task_id");


        if ($exist) { 
         return true; 
        }
        return false;
    }
    
    //============================================================================
    //  Function update_completeness() update task completeness in database
    //============================================================================      
    
     function update_completeness() {
      global $db;
      
      $completeness = $this->completeness;
      $task_id = $this->id;
      $team_id = $this->team_id;
             
           $sql = "UPDATE " . table_tasks . " SET task_completeness =$completeness WHERE task_id=$task_id AND task_team_id =$team_id";            
            
             if($db->query($sql)){   
               return true;     
          
             } 
               return false;        
     }   
    
      //========================================================================
      // Function save_tas_values()  sets values  and saves values to database
      //
      // @param $mode select if it is registration of new task or its update
      // @return ok if data are stored to database
      // @return error number if there was an error
      //========================================================================  
      
      function save_task_values($mode)
      {
          global $current_user;
                              
          $this->set_task_team_id($_REQUEST['id']);
          
          
          if ($mode == "save") {
              
              if ($this->duplicate_name()) { 
                  //task name already exists  
                  $team_error[] = 11;
                  return $team_error;
              }
          
          } else { 
              $this->set_task_id($_REQUEST['edit_task']);              
          }
              
          if ($mode == "save" || $mode == "update") {
          //set task values
          
          $this->set_task_name($_POST['task_name']);                    
          $this->set_task_deadline($_POST['task_deadline']);
          $this->set_task_worker($_POST['task_worker']);
          $this->set_task_description($_POST['task_description']);          
          
          }
             
          //store to database
          if (!$this->store()) { 
              //cannot save to dabase
              $team_error[] = 12;
              return $team_error;
          }
          return true;
      }
      
    
 
 //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 //  CHECKING FUNCTIONS
 //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     
      //==============================================================================
      //  Function get_tasks_data()  returns array of team tasks data
      //=============================================================================
      function get_tasks_data()
      {
          return $this->tasks_data;
      }
      
    //========================================================================
    // Function check_sorting() checks task sorting
    // @return true if sorting is selected and it is correct
    // @return false otherwise
    //========================================================================   
    
    function check_sorting() { 
        if (isset($_GET['sorttaskby'])){
         if (!ctype_digit(trim($_GET["sorttaskby"]))) {              
                header ('Location: ./attack.php?id=10');
                die;
                }
          return true;                                                                                       
         }
          return false;
    }
    
    //========================================================================
    // Function check_filtering() checks task filtering
    // @return true if filtering is used and it is correct
    // @return false otherwise
    //========================================================================   
    
    function check_filtering() { 
         if (isset($_GET['filtertaskby'])){
         if (!ctype_digit(trim($_GET["filtertaskby"]))) {
                header ('Location: ./attack.php?id=9');
                die;
                }
         if ($_GET['filtertaskby']>0){ 
               return true;  
         }      
         }
          return false;
    } 
    
    //============================================================================
    //  Function get_task_sorting() returns sort number if user selected some 
    //  sorting option sortby:
    //  1 = sorting by date ASC
    //  2 = sorting by date DESC (default)
    //  3 = sorting  by deadline desc
    //  4 = sorting by deadline asc
    //  5 = sorting by name desc
    //  6 = sorting by name asc
    //  7 = sorting by completeness ASC
    //  8 = sorting by completeness DESC
    //  @return ORDER BY statement
    //============================================================================  
        
    function get_sort() {
        if ($this->check_sorting()){
            $sort=$_GET['sorttaskby'];
            
            switch ($sort)
            {
            case 1 : 
            $order="ORDER BY task_date DESC";
            break;
            
            case 2 : 
            $order="ORDER BY task_date ASC";
            break;
            
            case 3 : 
            $order="ORDER BY task_deadline DESC";
            break;
            
            case 4 : 
            $order="ORDER BY task_deadline ASC";
            break;
            
            case 5 :             
            $order="ORDER BY task_name DESC";
            break;
            
            case 6 : 
            $order="ORDER BY task_name ASC";
            break;
            
            case 7 : 
            $order="ORDER BY task_completeness DESC";
            break;
            
            case 8 : 
            $order="ORDER BY task_completeness ASC";            
            break;            
        
            }                    
       } else {
       // nothing selected = ordering by task deadline ASC default
       $order = " ORDER BY task_deadline ASC";        
       }
      
       return $order;
    }
    
    //============================================================================
    //  Function get_filter() 
    // @return WHERE condition with specific user id
    // @return null if user does not select filter
    //============================================================================     
     
    function get_filter() {
     if ($this->check_filtering()){               
            
        $filter=$_GET['filtertaskby'];
        $where = "AND task_worker_id=$filter ";        
        return $where;
            
        }
    } 
      
    //========================================================================
    // Function check_task_name_exist() checks if task name exists
    // @return true if task name exists otherwise false
    //========================================================================    

    function check_task_name_exists() {
        if (!$_POST["task_name"]) {             
            return false;
            }
            return true;            
    }
    
    //========================================================================
    // Function check_task_name_exist() checks if task description exists
    // @return true if task descriptionexists otherwise false
    //========================================================================    

    function check_task_description_exists() {
        if (!$_POST["task_description"]) {             
            return false;
            }
            return true;            
    }   
    
    //========================================================================
    // Function check_task_name_length() checks task name length
    // @return true if name length is correct otherwise false
    //========================================================================    

    function check_task_name_length() {
        $team = new Team;
            if ($team->strlen_utf8(strip_tags(trim($_POST["task_name"]))) < $this->minimal_name_length) {       
                return false;
                }

            if ($team->strlen_utf8(strip_tags(trim($_POST["task_name"]))) > 25) {
                header ('Location: ./attack.php?id=16');
                die;
                }
            
            return true;
        
     }
     
     //========================================================================
    // Function check_task_description_length() checks task name length
    // @return true if name length is correct otherwise false
    //========================================================================    

    function check_task_desciption_length() {
             $team = new Team;
            if ($team->strlen_utf8(strip_tags(trim($_POST["task_description"]))) < $this->minimal_description_length) {
                return false;
                }

            if ($team->strlen_utf8(strip_tags(trim($_POST["task_description"]))) > 450) {
                header ('Location: ./attack.php?id=17');
                die;
                }
            
            return true;
        
     }

     //========================================================================
    // Function check_task_worker() checks task worker 
    // @return true if worker is selected otherwise false
    //========================================================================    

    function check_task_worker() {        
        if ($_POST["task_worker"] == null || $_POST["task_worker"] == 999) {            
            return false;
            } else {                
            if (check_integer($_POST["task_worker"])) {
                header ('Location: ./attack.php?id=18');
                die;
                }        
            }

        return true;    
    }
                           
    //========================================================================
    // Function check_task_deadline() checks task deadline if is correct
    // @return true if deadline is correct otherwise false
    //========================================================================    

    function check_task_deadline() {
   
    $regex="/^[0-3]{0,1}[0-9]{0,1}\/[0-1]{0,1}[0-9]{0,1}\/[2]{1}[0-9]{3}$/"; //regular expression for date xx/xx/xxxx
    $task_deadline = $_POST["task_deadline"];
    $date=$_POST["task_deadline"];
     
                    
    if($task_deadline == null || !preg_match($regex,$task_deadline)){
       
     return false;    
    } else {
        
        $first_slash_pos = strpos($date,"/"); 
        $second_slash_pos = strrpos($date,"/");
        $date_length = strlen($date);
      
        $day = substr($date,0,$first_slash_pos);      
        $month = substr($date,$first_slash_pos+1,$second_slash_pos-$first_slash_pos-1); 
        $year = substr($date,$second_slash_pos+1); 
        if ($year > 2030) {
         return false;   
        }
         if (checkdate($month,$day,$year)){
           
            return true;   
         }
        
        return false;
    
    }
      
    }
    
    
    //========================================================================
    // Function check_task_completeness() checks task completeness if is correct
    // @return true if completeness is correct otherwise false
    //========================================================================    

    function check_task_completeness($task_completeness) {       
  
        
    
        if($task_completeness == null || !ctype_digit($task_completeness) || $task_completeness < 0 || $task_completeness > 100){      
          return false;    
        }
          return true;
        
    }
    
    //========================================================================
    // Function refresh_team_modification() set new last modification date    
    //========================================================================      
 
    function refresh_task_modification($task_id,$team_id) {
        global $db;
        $task_last_modify = time();        
        $db->query("UPDATE " . table_tasks . " SET task_last_modify = FROM_UNIXTIME($task_last_modify) WHERE task_id=$task_id AND task_team_id=$team_id");
        
        
    } 
    
    //========================================================================
    // Function is_task_worker() checks if current user is a task worker
    // if yes then return true otherwise false    
    //========================================================================      
 
    function is_task_worker() {
        global $current_user;
                                         
        if ($current_user->user_id == $this->worker_id) {
            return true;   
        }
            return false;
        
        
    }
    //============================================================================
    //  Function get_tasks_data() returns task ids array    
    //============================================================================      
    function get_tasks_ids() {
     return $this->tasks_ids;
    } 
    
    //============================================================================
    //  Function get_user_tasks() returns user tasks  array    
    //============================================================================      
    function get_user_tasks() {
     return $this->user_tasks;
    } 
    
    //============================================================================
    //  Function get_user_tasks() returns user team tasks ids (array) 
    //============================================================================      
    function get_user_team_tasks() {
     return $this->user_team_tasks;
    } 
    
    //============================================================================
    //  Function get_team_member_task_creation() returns true if user can add task to
    //  himself
    //============================================================================      
    function get_team_member_task_creation() {
        $allowed=$this->team_member_own_task;
     return $allowed;
    } 
      
 //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 //  SETTING FUNCTIONS
 //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   
    //============================================================================
    //  Function set_task_id() sets task id
    //  @param task_id
    //============================================================================      
    function set_task_id($task_id) {
     $this->id = $task_id;
    } 
    
    //============================================================================
    //  Function set_task_team_id() sets task team id
    //  @param team_id
    //============================================================================      
    function set_task_team_id($team_id) {
     $this->team_id = $team_id;
    } 
    
    
    //============================================================================
    //  Function set_task_creator() sets creator id
    //  @param creator_id
    //============================================================================      
    function set_task_creator($creator_id) {
     $this->creator_id = $creator_id;
    }  
    
    //============================================================================
    //  Function set_task_name() sets task name
    //  @param task_name
    //============================================================================      
    function set_task_name($task_name) {
        global $db;
        
     $this->name = htmlspecialchars($db->escape(strip_tags($task_name)));
    } 
    
    //============================================================================
    //  Function set_task_description() sets task description
    //  @param task_description
    //============================================================================      
    function set_task_description($task_description) {
        global $db;    
                       
    
     $this->description = htmlspecialchars($db->escape(strip_tags($task_description)));
    }                                     
    
    //============================================================================
    //  Function set_task_completeness() sets task completeness 
    //  @param task_completeness
    //============================================================================      
    function set_task_completeness($task_completeness) {
     $this->completeness = $task_completeness;
    } 
    
        //============================================================================
    //  Function set_task_rating() sets task rating 
    //  @param task_rating
    //============================================================================      
    function set_task_worker($task_worker) {
     $this->worker_id= $task_worker;
    } 
    //============================================================================
    //  Function set_task_deadline() sets task deadline 
    //  @param task_deadline
    //============================================================================      
    function set_task_deadline($task_deadline) {
        
        $first_pos = strpos($task_deadline,'/');
        $last_pos = strrpos($task_deadline,'/');

        $day =  substr($task_deadline,0,$first_pos);
        $month = substr($task_deadline,$first_pos+1,strlen(substr($task_deadline,0,$last_pos))-strlen(substr($task_deadline,0,$first_pos+1)));
        $year = substr($task_deadline,$last_pos+1,4);           
        
        $date = $year."-".$month."-".$day;
        
        $this->deadline=$date;

    } 
    
}
?>

